const path = require('path');
// @rollup/plugin-node-resolve 可以外部的依赖打包在我们的项目中
// tree-shaking commonjs使用 exports.a = 1  es  使用 export const a = 1  使用解构赋值引用
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const { babel } = require('@rollup/plugin-babel');
const json = require('@rollup/plugin-json');
// 支持vue 的语法
const vue = require('rollup-plugin-vue');
const postcss = require('rollup-plugin-postcss');
const inputPath = path.resolve(__dirname, './src/index.js');
const outputUmdPath = path.resolve(__dirname, './dist/tsai-datav.js');
const outputEsPath = path.resolve(__dirname, './dist/tsai-datav.es.js');
const outputCjsPath = path.resolve(__dirname, './dist/tsai-datav.cjs.js');

console.log(babel);
module.exports = {
  input: inputPath,
  output: [
    {
      file: outputUmdPath,
      format: 'umd',
      name: 'tsaiDatav',
      globals: {
        vue: 'Vue',
      },
    },
    {
      file: outputEsPath,
      format: 'es',
    },
    {
      file: outputCjsPath,
      format: 'cjs',
    },
  ],
  plugins: [
    // 是有顺序的
    vue(),
    nodeResolve(),
    commonjs(),
    babel({
      exclude: 'node_modules/**',
      babelHelpers: 'bundled',
    }),
    json(),
    postcss({
      plugins: [],
    }),
  ],
  // 外部引用的某些依赖 不打包进自己的组件库中。减少冗余代码
  external: ['vue'],
};
